var Common = require('../../utils/common.js');
import create from '../../utils/create2.js'
import store from '../../store/index.js'
const { $Toast } = require('../../component/base/index');
create(store, {
  /**
   * 页面的初始数据
   */
  data: {
    tasting: {},
    show: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { id, sale } = options
    Common.my_request({
      url: '/AppMaster/BookDinner/getBookDinnerOrderInfo',
      data: {
        book_id: id
      },
      success: (res) => {
        const { data, result, message } = res.data
        if (result === 0) {
          this.store.data.tasting = data
          this.store.data.tasting['sale'] = sale
          this.update()
        } else {
          Common.Alert('提示', message);
        }
      }
    });
  },
  submitHandler(e) {
    const { value } = e.detail
    const { name, phone } = value
    const phonetest = /^0?1\d{10}$/;
    if (name === '') {
      Common.Alert('提示', '请输入姓名');
      return false;
    }
    if (phone === '') {
      Common.Alert('提示', '请输入手机号');
      return false;
    }
    if (!phonetest.test(phone)) {
      Common.Alert('提示', '请输入正确的手机号码');
      return false;
    }
    Common.my_request({
      url: '/AppMaster/Taste/judgeJoin',
      data: {
        id: this.store.data.tasting.judge_id,
        salesman_id: this.store.data.tasting.sale,
        name, phone
      },
      success: (res) => {
        const { data, result, message } = res.data
        if (result === 0) {
          this.setData({
            show: true
          })
        } else {
          Common.Alert('提示', message);
        }
      }
    });
  },
  goHome() {
    wx.switchTab({
      url: '/pages/index/index',
    })
  }
})